package com.javaapi.string;

import java.io.File;
import java.io.ObjectInputStream.GetField;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class TestString {
	public String getVideosNames() {
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
		return simpleDateFormat.format(date);
	}

	public boolean isNumeric(String s) {
		try {
			Integer.parseInt(s);
		} catch (NumberFormatException e) {
			return false;
		} catch (NullPointerException e) {
			return false;
		}
		return true;
	}

	public static String getStrTime(String cc_time) {
		String re_StrTime = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
		// 例如：cc_time=1291778220
		long lcc_time = Long.valueOf(cc_time);
		re_StrTime = sdf.format(new Date(lcc_time * 1000L));
		return re_StrTime;
	}

	public static String join(String srcStr, String tarStr) {

		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < tarStr.length(); i++) {
			if (i == tarStr.length()) {
				break;
			}
			sb.append(tarStr.charAt(i));
			sb.append(srcStr);
		}

		return sb.toString();
	}

	public static void main(String[] args) {
		String str1 = "2|33|4";
		String str2 = "a=1 and b =2 or c=3";
		String[] str1Array = str1.split("\\|");
		String[] str2Array = str2.split("and|or");
		for (int i = 0; i < str1Array.length; i++) {
			System.out.print(str1Array[i]);
			System.out.println(str2Array[2]);
		}
		TestString ts = new TestString();
		System.out.println(ts.getVideosNames());
		System.out.println(ts.isNumeric("adlk123"));
		System.out.println(System.currentTimeMillis());
		System.out.print(String.valueOf(System.currentTimeMillis()));
		File file = new File("D:\\workspace");
		System.out.println(file.getPath());
		System.out.println(1 >> 1);
		System.out.println(1 << 1);
		Random random = new Random();

		System.out.println(random.nextInt() + "--");
		System.out.println(random.nextInt(6));

		String VERSION = String.valueOf(12);
		String strFormat = String.format("android-async-http/%s (http://loopj.com/android-async-http)", VERSION);
		System.out.println(strFormat);
		System.out.println(String.format("%1$,09d", -3123));
		System.out.println(String.format("%1$9d", -31));
		System.out.println(String.format("%1$-9d", -31));
		System.out.println(String.format("%1$(9d", -31));
		System.out.println(String.format("%1$#9x", 5689));

		Calendar c = Calendar.getInstance();
		String date = c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DAY_OF_MONTH);
		System.out.println(date);

		Calendar ca = Calendar.getInstance();
		int year = ca.get(Calendar.YEAR); // 获取年份
		int month = ca.get(Calendar.MONTH); // 获取月份
		int day = ca.get(Calendar.DATE); // 获取日
		int hour = ca.get(Calendar.HOUR); // 获取小时
		int minute = ca.get(Calendar.MINUTE); // 获取分
		int second = ca.get(Calendar.SECOND); // 获取秒
		int millisecond = ca.get(Calendar.MILLISECOND); // 获取毫秒

		String da = "" + year + (month + 1) + day + hour + minute + second + millisecond;
		System.out.println(da);
	}
	// public String timeformat(long time){
	// millis
	// }
}
